/***************************************************************
*  Copyright (c) 2007 by GroupMe! Team (www.groupme.net)
*  All rights reserved.
*
*  This file is part of the GroupMe! Project. Source code of 
*  this project is closed and redistribution of this code is
*  prohibited. 
*  
*  Contact: http://www.groupme.net
*
*  This copyright notice MUST APPEAR in all copies of the file!
***************************************************************/
package net.groupme.search.publication;

/**
 * created on Jul 31, 2007
 * 
 * This class defines some constants for the {@link PublicationSearchEngine} class.
 * 
 * @author Fabian Abel, <a href="mailto:abel@l3s.de">abel@l3s.de</a>
 * @author last edited by: $Author: fabian $
 * 
 * @version $Revision: 1.1 $ $Date: 2007-08-01 09:57:53 $
 */
public class PUBLICATION_ENGINE_VOCABULARY {
	/** allowed search strategies at CiteULike.org (and their indicator-strings) */
	public enum CiteULikeSearchStrategy{
		/** Indicates to search for tags at CiteULike. */
		TAG("tag"),
		/** Indicates to search within the abstract of publications at CiteULike. */
		ABSTRACT("abstract"),
		/** Indicates to search for publications that were published in a certain journal  */
		JOURNAL("journal"),
		/** Indicates to search for publications that have a certain author*/
		AUTHOR("last_name"),
		/** Indicates to search for publications that contain the keyword within the title*/
		TITLE("title");
		
		/** the CiteULike search strategy indicator */
		private String strategy = null;
		private CiteULikeSearchStrategy(String strategy){
			this.strategy = strategy;
		}
		/** returns the search strategy indicator */
		public String getStrategyIndicator(){
			return this.strategy;
		}
	}

	/** Basic URL which initiates a CiteULike search when appending a search strategy (by tag, author, ..) and some
	 *  keywords. Calling this URL (with some keywords and a search strategy indicator) results in an RSS feed (RSS 1.0) */
	private static final String CITEULIKE_SEARCH_URL_WITH_RSS_EXPORT = "http://www.citeulike.org/rss/search/all?f=";
	
	/** append the username to get the user's cites (at CiteULike) as an RSS feed. */
	private static final String CITEULIKE_USER_URL_WITH_RSS_EXPORT = "http://www.citeulike.org/rss/user/";

	/** by appending the ID of an article you get the URL which points to the BibTex-file of article
	 *  For example: <code>http://www.citeulike.org/bibtex/article/975464</code> */
	private static final String CITEULIKE_BIBTEX_ARTICLE_EXPORT_INDICATOR = "http://www.citeulike.org/bibtex/article/";
	
	/**
	 * Returns the URL which will cause a search at CiteULike with the given keywords. 
	 * Calling this URL results in an RSS feed (RSS 1.0).
	 * 
	 * @param keywords the keywords as single string (e.g.: <i>social+semantic+web</i> or <i>social semantic web</i>) 
	 * @param strategy the search strategy, e.g. keywords should be part of the title, thus: {@link CiteULikeSearchStrategy#TITLE}.
	 * @return the URL which will cause a search at CiteULike with the given keywords.
	 */
	public static final String getCiteULikeSearchURL(String keywords, CiteULikeSearchStrategy strategy){
		return CITEULIKE_SEARCH_URL_WITH_RSS_EXPORT + strategy.getStrategyIndicator() + "&q=" + prepareKeywordQuery(keywords);
	}
	
	/**
	 * Returns the URL which refers to the RSS feed (RSS 1.0) of a user containing his cites at CiteULike.
	 * 
	 * @param username a CiteULike username
	 * @param tag a single tag if only those cites which are tagged with this tag should be returned otherwise this
	 * parameter should be <code>null</code> or empty
	 * @return the URL which refers to the RSS feed (RSS 1.0) of a user containing his cites at CiteULike.
	 */
	public static final String getCiteULikeUserCitesURL(String username, String tag){
		if(tag == null){
			tag = "";
		}
		return CITEULIKE_USER_URL_WITH_RSS_EXPORT + CiteULikeSearchStrategy.TAG.getStrategyIndicator() + "/" + tag;
	}
	
	/**
	 * Returns the BibTex-URL that corresponds to the given article.
	 * @param articleURL the URL that points to an article. It has be something like:
	 * <pre>
	 *   http://www.citeulike.org/[optional patterns]/article/[article id]
	 * </pre>
	 * Examples:
	 * <pre>
	 *   http://www.citeulike.org/article/975464
	 *   http://www.citeulike.org/user/isera/article/1455785
	 * </pre>
	 * @return the BibTex-URL that corresponds to the given article.
	 */
	public static final String getBibTexURL(String articleURL){
		return CITEULIKE_BIBTEX_ARTICLE_EXPORT_INDICATOR + articleURL.substring(articleURL.indexOf("article/") + 8);
	}
	
	/**
	 * Reformats the given query keywords so that it can be used within an URL
	 * @param keywords the keywords..
	 * @return the cleand query keyword string
	 */
	private static final String prepareKeywordQuery(String keywords){
		keywords = keywords.replaceAll(" ", "+");
		keywords = keywords.replaceAll("\"", "%22");
		return keywords;
	}
	
}
